package com.foreknow.hospital.controller;

import com.foreknow.hospital.po.Hospital;
import com.foreknow.hospital.service.HospitalService;
import com.foreknow.hospital.service.impl.HospitalServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class HospitalController {
    /**
     * HttpServletRequest Servlet中的请求对象
     * 里面会提供一方法，用于获取前端传递到后台的请求参数
     * 客户端向服务问端请求的URL地址
     *  http://localhost:8080/hospital/BusinessController/listBusinessByOrderTypeId?orderTypeId=1
     * @param request
     * @return
     */
    public Object listHospitalByOrderTypeId(HttpServletRequest request) {
        //1. 获取前台的请求参数
        String orderTypeId = request.getParameter("orderTypeId");
        //2. 调用Service中的方法
        HospitalService hospitalService = new HospitalServiceImpl();
        List<Hospital> list = hospitalService.listHospitalByOrderTypeId(Integer.parseInt(orderTypeId));
        return list;
    }

    /**
     * 根据商家编号查询商家信息
     * 前端发送的URL地址：
     * http://localhost:8080/hospital/BusinessController/getBusinessById?businessId=10001
     * @param request
     * @return
     */
    public Object getHospitalById(HttpServletRequest request) {
        HospitalService businessService = new HospitalServiceImpl();
        Hospital hospital= new Hospital();
        hospital.setHpId(Integer.parseInt(request.getParameter("hpId")));
        Hospital hpi =HospitalService.getHospitalById(hospital);
        return hpi;
    }

}
